<template>
	<view class="wrapper">
		
		<view class="content">
			<view class="tab-cont">
				<block v-if="couponList.length">
					<view v-for="(item,index) in couponList" :key="index" class="coupon-item">
						<view class="coupon-left">
							<view class="coupon-num">
								<view class="unit">￥</view>
								<view class="num">{{item.reduce}}</view>
							</view>
							
							<view class="coupon-text">
								<view class="coupon-t">{{item.title}}</view>
								<view class="coupon-time">{{item.time_day}}前</view>
							</view>
						</view>
						
						<view  @click="delBtn(item.coupon_id)" class="coupon-delete">删除</view>
					</view>
				</block>
				<view v-else class="no-more">
					暂无数据
				</view>
			</view>
		</view>
		
		<view @click="addBtn" class="add-btn">
			新增
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {	
				couponList:[]
			}
		},
		onLoad() {
			
		},
		onShow(){
			this.getList()
		},
		methods: {
			getList(){
				this.api._post('/Coupon/couponList').then(res=>{
					this.couponList=res.data
				})
			},
			delBtn(id){
				this.api._post('/Coupon/couponDel',{
					coupon_id:id
				}).then(res=>{
					if(res.status==1){
						this.$refs.uToast.show({
							title: res.message,
							type: 'success',
						})
						this.getList()
					}else{
						this.$refs.uToast.show({
							title: res.message,
							type: 'error',
						})
					}
				})
			},
			// 新增
			addBtn(){
				uni.navigateTo({
					url:'./addCoupon'
				})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	@import url('../../common/common.css');
	
	.content {
		padding: 20upx;
	}
	
	.coupon-item {
		margin-bottom: 20upx;
		padding: 30upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-image: url(~@/static/images/coupon.png);
		background-size: 100% 100%;
		.coupon-left {
			display: flex;
			align-items: center;
			width: 79%;
			border-right: 1upx solid #f10000;
			.coupon-num {
				display: flex;
				align-items: baseline;
				color: #f70000;
				font-weight: bold;
				line-height: 50upx;
				.unit {
					font-size: 30upx;
				}
				.num {
					font-size: 50upx;
				}
			}
			.coupon-text {
				margin-left: 70upx;
				.coupon-t {
					font-size: 28upx;
					line-height: 45upx;
					color: #f70000;
				}
				.coupon-time {
					font-size: 24upx;
					line-height: 45upx;
					color: #f70000;
				}
			}
		}
		.coupon-delete {
			width: 110upx;
			height: 46upx;
			border-radius: 25upx;
			border: 2upx solid #f70000;
			font-size: 24upx;
			font-weight: bold;
			text-align: center;
			line-height: 46upx;
			letter-spacing: 1px;
			color: #f70000;
		}
	}
	.state {
		font-size: 24upx;
		color: #ff9494;
		text-align: center;
		line-height: 40upx;
	}
	.add-btn{
		width: 100%;
		height: 100upx;
		line-height: 100upx;
		text-align: center;
		color: #FFFFFF;
		background: #F70000;
		position: fixed;
		bottom: 0;
		left: 0;
	}
	.no-more{
		margin: 50upx auto;
		text-align: center;
		font-size: 28upx;
		color: #999999;
	}
</style>
